//
//  WaterPush2.m
//  puBuLiu
//
//  Created by douya on 15/1/4.
//  Copyright (c) 2015年 douya. All rights reserved.
//

#import "WaterPush2.h"
#import "UIImageView+OutWhiteFrame.h"
@implementation WaterPush2

+(WaterPush2 *)createPush:(CGRect)frame
{
//    UIScrollView *myScrollView;
    
    float colHeight[3];
    float endImageWidth;
    int off_width;//图片的间距 横
    int off_height;//图片的间距 竖
    int sectionNum;
    
    WaterPush2 *push=[[WaterPush2 alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];

    
    //设置列个数
    sectionNum=2;
    colHeight[0]=0.0f;
    colHeight[1]=0.0f;
    colHeight[2]=0.0f;
    //   图片间距
    off_width=10;
    off_height=20;
    
    //图片宽度
    endImageWidth=140;

//    myScrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320, 480)];
    push.backgroundColor=[UIColor greenColor];
//    [view addSubview:myScrollView];
    
    for (int i=1; i<15; i++)
    {
        float imageWidth=(320-2*off_width)/sectionNum;
        float imageHeight=arc4random()%100+150;
        
        float endHeight=endImageWidth*imageHeight/imageWidth;
        
        int index=colHeight[0]<colHeight[1]?0:1;
        
        UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(off_width+(endImageWidth+2*off_width)*index, colHeight[index]+44, endImageWidth, endHeight)];
        
        [push addSubview:imageView];
        
        //设置图片的边框
        [imageView AddOutFrame:[UIColor whiteColor] Width:5];
        //重新计算当前列的总高度(一共有两列  左右两列)
        colHeight[index]=colHeight[index]+endHeight+off_height;
    }
    //最后再计算滑动视图的总高度 看是左边列高还是右边列高 选出最高的列出来
    float endScrollHeight=colHeight[0]<=colHeight[1]?colHeight[1]:colHeight[0];
    
    push.contentSize=CGSizeMake(320, endScrollHeight+100);

    return push;
}
@end
